package com.wei.schedule;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.wei.service.DailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author wjx
 * @ClassName ScheduleTask
 * @description: TODO
 * @date 2022-12-05 04:58
 * @version: 1.0
 */
@Component
public class ScheduleTask {

    @Autowired
    private DailyService statisticsDailyService;

    /**
     * 每天凌晨1点执行定时任务
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void task2() {
        //获取上一天的日期

        // 1.年-月-日 时:分:秒
        DateTime dateTime = DateUtil.offsetDay(new Date(), -1);

        // 2.年-月-日
        String day = DateUtil.formatDate(dateTime);

        statisticsDailyService.createStatistics(day);
    }
}
